<%@page import="com.mrjy.common.entity.OrderInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<html>
<head>
    <title>My JSP 'OutDemo.jsp' starting page</title>
</head>

<body ontouchstart>
<div class="container" id="container">
    <div class="header back-color-5AC9BD">
        <!--<span class="turn-back"><img src="weCommon/img/icon/turn-back-icon.png"></span>-->
        <span class="header-title">365微信支付</span>
    </div>
    <div id="qrcode"></div>
    <%
        int all = out.getBufferSize();//获得缓冲区大小
        int remain = out.getRemaining();//获得剩余缓冲区大小
        int use = all - remain;//使用的缓冲区大小
        out.println("使用的缓冲区大小" + use);
    %>
</div>

<script src="../common/js/qrcode.js"></script>
<script type="text/javascript" src="../common/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<script type="text/javascript" src="../common/js/common.url.js"></script>
<script type="text/javascript" src="../common/js/common.fun.js"></script>
<script type="text/javascript" src="../common/js/payment_weixin.js"></script>
<script type="text/javascript">
    var paymentData = {
        "name": getQueryString2("name"),
        "money": getQueryString("money"),
        "orderCode": getQueryString("orderCode"),
        "className": getQueryString("className"),
        "wxnotify_url": getQueryString("wxnotify_url"),
        //"userId": getQueryString("userId"),
        "messageString": getQueryString("messageString")
    }
    var returnUrl = getQueryString("returnUrl");

    $(function(){
        doWxPay();
    });
    /*通过传过来的openid去决定要不要手动获取openid*/
    function doWxPay(){
        var openid = getQueryString("openid");
        if(openid){
            var _data = {
                "name": getQueryString2("name"),
                "money": getQueryString("money"),
                "orderCode": getQueryString("orderCode"),
                "className": getQueryString("className"),
                "wxnotify_url": getQueryString("wxnotify_url"),
                //"userId": getQueryString("userId"),
                "openid": openid,
//						"openid":"o6DVnw3xWVB-ek7yWqXZeJDngoDo",
                "messageString": getQueryString("messageString")
            }
            console.log("22222222")
            weixinPay.doWeixinPayBusiness(_data, decodeURIComponent(returnUrl),function (data) {
                console.log(data);
                console.log(data.code_url)
                new QRCode(document.getElementById('qrcode'), data.code_url);
                //关键在这里，Ajax定时访问服务端，不断获取数据 ，这里是1秒请求一次。
//                weixinPayRecode(data.code);
            });
        }else{
            getOpenId();
        }
    }
    /*非微信服务号接口*/
    function getOpenId(){
        var code = getQueryString("code");
        $.getJSON(mrjyUrl + "common/payment/getOpenid.do",{
            "code": code
        },function(data){
            var oauthObj = JSON.parse(data);
            console.log(oauthObj)
            paymentData.openid = oauthObj.openid;
            //paymentData.openid = "o6DVnw3xWVB-ek7yWqXZeJDngoDo";
            console.log(decodeURIComponent(returnUrl));
            weixinPay.doWeixinPayBusiness(paymentData, decodeURIComponent(returnUrl));
        });
    }

  /*  function weixinPayRecode(obj) {
        var timesRun=0;

        var interval = setInterval(function(){
            timesRun += 1;
            if(timesRun === 60){
                clearInterval(interval);
            }else{
                $.getJSON(mrjyUrl + "payment/userBalance/WXPollingNotify.do",{
                    "out_trade_no": obj
                },function(data){
                    console.log(data)
                    if (data.indexOf('OK')>0){
                        console.log('OK');
                        clearInterval(interval);
                    }
                });
            }
        }, 5000);
    }*/
</script>
</body>
</html>